package cj.web.admin.dao;
/*
 *  
 *  
*/
import java.util.List;

import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.ReturnGeneratedKeys;
import net.paoding.rose.jade.annotation.SQL;
import net.paoding.rose.jade.annotation.SQLParam;
import cj.web.admin.domain.News;

/**
 * 
 * @author 
 *
 */
@DAO
public interface NewsDAO{
    
    @SQL("select * from News where id=:1")
    News queryById(int id);
    
    @ReturnGeneratedKeys
    @SQL("INSERT INTO News (id,type,columnsId,subjectId,title,keywords,abstractInfor,vedioUrl,carouselImage,content,author,status,releaseState #if(:t.releaseAt!=''){,releaseAt},isTop,isOuterLink,outerLinkUrl,stickAt,pvNum,pvNumFinal,praiseNum,commentsNum,forwardNum,collectNum,deleteFlag,createUser,createAt,updateUser,updateAt,isComments, label, source, voteId) "
    		+ "VALUES (:t.id,:t.type,:t.columnsId,:t.subjectId,:t.title,:t.keywords,:t.abstractInfor,:t.vedioUrl,:t.carouselImage,:t.content,:t.author,:t.status,:t.releaseState #if(:t.releaseAt!=''){,:t.releaseAt},:t.isTop,:t.isOuterLink,:t.outerLinkUrl,:t.stickAt,:t.pvNum,:t.pvNumFinal,:t.praiseNum,:t.commentsNum,:t.forwardNum,:t.collectNum,:t.deleteFlag,:t.createUser,:t.createAt,:t.updateUser,:t.updateAt,:t.isComments,:t.label, :t.source, :t.voteId)")
    int create(@SQLParam("t") News news);
	//stickAt=:t.stickAt,status=:t.status,releaseAt=:t.releaseAt,isTop=:t.isTop,isComments=:t.isComments,deleteFlag=:t.deleteFlag,updateUser=:t.updateUser,
	@SQL("UPDATE News SET source=:t.source,status=:t.status,type=:t.type,columnsId=:t.columnsId,subjectId=:t.subjectId,title=:t.title,keywords=:t.keywords,abstractInfor=:t.abstractInfor,vedioUrl=:t.vedioUrl,carouselImage=:t.carouselImage,content=:t.content,releaseState=:t.releaseState,isOuterLink=:t.isOuterLink,outerLinkUrl=:t.outerLinkUrl,label=:t.label, #if(:t.releaseAt!=''){releaseAt=:t.releaseAt,} updateUser=:t.updateUser,updateAt=:t.updateAt,voteId=:t.voteId WHERE id=:t.id")
    void update(@SQLParam("t") News news);
	
	@SQL("UPDATE News SET source=:t.source,type=:t.type,columnsId=:t.columnsId,subjectId=:t.subjectId,title=:t.title,keywords=:t.keywords,abstractInfor=:t.abstractInfor,vedioUrl=:t.vedioUrl,carouselImage=:t.carouselImage,content=:t.content,isOuterLink=:t.isOuterLink,outerLinkUrl=:t.outerLinkUrl,label=:t.label, #if(:t.releaseAt!=''){releaseAt=:t.releaseAt,} updateUser=:t.updateUser,updateAt=:t.updateAt,voteId=:t.voteId WHERE id=:t.id")
    void updateNoUpStatus(@SQLParam("t") News news);
    
    @SQL("UPDATE News SET deleteFlag=0 WHERE id=:1")
    void deleteById(int id);

    @SQL("select id,type,subjectId,columnsId,keywords,title,abstractInfor,author,status,releaseState,releaseAt,label,isTop,isComments,stickAt,praiseNum,commentsNum,collectNum from News where deleteFlag=1 and createUser=:t.createUser and releaseState in (0,3) #if(:t.title!=''){ and title like '%##(:t.title)%' } ORDER BY releaseState desc,createAt desc limit :t.start,:t.length;")
	List<News> getList(@SQLParam("t")News news);

    @SQL("select count(1) from News where deleteFlag=1 and createUser=:t.createUser and releaseState in (0,3) #if(:t.title!=''){ and title like '%##(:t.title)%' }")
	int getListSize(@SQLParam("t")News news);
    
    //------------
    @SQL("select id,type,subjectId,columnsId,keywords,title,abstractInfor,author,status,releaseState,releaseAt,label,isTop,isComments,stickAt,praiseNum,commentsNum,collectNum from News where deleteFlag=1 and releaseState in (2) #if(:t.title!=''){ and ( title like '%##(:t.title)%' or keywords like '%##(:t.title)%' ) } #if(:t.columnsId>-1){ and columnsId=:t.columnsId} ORDER BY releaseState desc,createAt desc limit :t.start,:t.length;")
	List<News> getUpNewsList(@SQLParam("t")News news);

    @SQL("select count(1) from News where deleteFlag=1 and releaseState in (2) #if(:t.title!=''){ and ( title like '%##(:t.title)%' or keywords like '%##(:t.title)%' ) } #if(:t.columnsId>-1){ and columnsId=:t.columnsId}")
	int getUpNewsListSize(@SQLParam("t")News news);
    //------------
    
    @SQL("select id,type,subjectId,columnsId,keywords,title,abstractInfor,author,status,releaseState,releaseAt,label,isTop,isComments,stickAt,praiseNum,commentsNum,collectNum,pvNum,forwardNum from News where deleteFlag=1 and createUser=:t.createUser and releaseState=:t.releaseState #if(:t.title!=''){ and title like '%##(:t.title)%' } ORDER BY releaseState desc,createAt desc limit :t.start,:t.length;")
	List<News> getListByState(@SQLParam("t")News news);

    @SQL("select count(1) from News where deleteFlag=1 and createUser=:t.createUser and releaseState=:t.releaseState #if(:t.title!=''){ and title like '%##(:t.title)%' }")
	int getListSizeByState(@SQLParam("t")News news);

    @SQL("UPDATE News SET source=:t.source,releaseState=:t.releaseState,status=:t.status,isTop=:t.isTop,isComments=:t.isComments,updateUser=:t.updateUser,updateAt=:t.updateAt WHERE id=:t.id")
	void down(@SQLParam("t")News news);

    @SQL("select id,type,columnsId,subjectId,keywords,title,abstractInfor,author,status,releaseState,releaseAt,label,isTop,isComments,stickAt,praiseNum,commentsNum,collectNum,pvNum,forwardNum,createAt from News where deleteFlag=1 and columnsId=:t.columnsId and releaseState=:t.releaseState #if(:t.title!=''){ and title like '%##(:t.title)%' } #if(:2!=''){ and createAt>=:2 } #if(:3!=''){ and createAt<=:3 } ORDER BY stickAt desc, releaseAt desc limit :t.start,:t.length;")
	List<News> getListByColumnsId(@SQLParam("t")News news, String begin, String end);

    @SQL("select count(1) from News where deleteFlag=1 and columnsId=:t.columnsId and releaseState=:t.releaseState #if(:t.title!=''){ and title like '%##(:t.title)%' } #if(:2!=''){ and createAt>=:2 } #if(:3!=''){ and createAt<=:3 } ")
	int getListSizeByColumnsId(@SQLParam("t")News news, String begin, String end);

    @SQL("UPDATE News SET stickAt=now(),updateAt=now() WHERE id=:1")
	void updateByStickTime(int id);

    @SQL("UPDATE News SET stickAt=null,updateAt=now() WHERE id=:1")
	void updateByStickTimeIsNull(int id);

    @SQL("UPDATE News SET isTop=:t.isTop,updateAt=now() WHERE id=:t.id")
	void updateIsTop(@SQLParam("t")News obj);

    @SQL("UPDATE News SET pvNum=:t.pvNum,updateAt=now() WHERE id=:t.id")
	void updatePV(@SQLParam("t")News news);

    @SQL("UPDATE News SET isComments=:t.isComments,updateAt=now() WHERE id=:t.id")
	void updateIsComments(@SQLParam("t")News obj);
}